import { http } from "@/utils/http";

/** 标签查询条件 */
export interface TagQuery extends BasePageQuery {
  // 可根据实际需求添加查询参数
  tagName?: string;
  tagType?: string;
  belongDept?: number;
}

/** 标签DTO */
export interface TagDTO {
  tagId: number;
  tagName: string;
  tagType?: string;
  sort?: number;
  remark?: string;
  createTime?: string;
  updateTime?: string;
}

/** 添加标签命令 */
export interface TagAddCommand {
  tagName: string;
  tagType?: string;
  sort?: number;
  remark?: string;
}

/** 修改标签命令 */
export interface TagUpdateCommand {
  tagId: number;
  tagName: string;
  tagType?: string;
  sort?: number;
  remark?: string;
}

/** 获取标签列表 */
export const getTagListApi = (params?: TagQuery) => {
  return http.request<ResponseData<PageDTO<TagDTO>>>(
    "get",
    "/system/tags",
    {
      params
    }
  );
};

/** 从从库获取标签列表（示例） */
export const getTagListFromSlaveApi = (params?: TagQuery) => {
  return http.request<ResponseData<PageDTO<TagDTO>>>(
    "get",
    "/system/tags/database/slave",
    {
      params
    }
  );
};

/** 根据标签ID获取详情 */
export const getTagInfoApi = (tagId: number) => {
  return http.request<ResponseData<TagDTO>>(
    "get",
    `/system/tags/${tagId}`
  );
};

/** 新增标签 */
export const addTagApi = (data: TagAddCommand) => {
  return http.request<ResponseData<void>>(
    "post",
    "/system/tags",
    {
      data
    }
  );
};

/** 修改标签 */
export const updateTagApi = (tagId: number, data: TagUpdateCommand) => {
  // 确保data中包含tagId
  data.tagId = tagId;
  return http.request<ResponseData<void>>(
    "put",
    `/system/tags/${tagId}`,
    {
      data
    }
  );
};

/** 删除标签 */
export const deleteTagApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>(
    "delete",
    "/system/tags",
    {
      params: {
        // 需要将数组转换为字符串  否则Axios会将参数变成 tagIds[0]:1  tagIds[1]:2 这种格式，后端接收参数不成功
        tagIds: data.toString()
      }
    }
  );
};
